#include"Thread.hpp"

int tickes = 10000;

pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;

void* ThreadRoutine(void* args)
{
  string message = static_cast<const char*>(args);
  while(true)
  {  
    pthread_mutex_lock(&mutex);
    if(tickes > 0)
    {
      cout << message << " get tickets " << tickes-- << endl;
    }
    else
    {
      pthread_mutex_unlock(&mutex);
      break;
    }
    pthread_mutex_unlock(&mutex);
  }
  return nullptr;
}


int main()
{
  Thread t1(1,ThreadRoutine,(void*)"thread->1");
  Thread t2(2,ThreadRoutine,(void*)"thread->2");
  Thread t3(3,ThreadRoutine,(void*)"thread->3");
  
  t1.run();
  t2.run();
  t3.run();

  t1.join();
  t2.join();
  t3.join();
    
  return 0;
}




